package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.utils.ResultVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
//@RestController  异步请求，合二为一
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping (value = "/login",method = RequestMethod.GET)
    public ResultVO login(String username, String password) {
        return userService.login(username, password);
    }

    @RequestMapping("/register")
    public ResultVO register(User user){
        int result = userService.register(user);
        if(result>0){
            return new ResultVO(1003,"注册成功",null);
        }else{
            return new ResultVO(1004,"注册成功",null);
        }
    }
}
